<template>
  <div>
    <el-container class="home-container">
      <el-aside width="180px" class="home-aside">
        <div style="background-color: #20a0ff;width: 100%;height: 60px;">
          <i><img src="../../static/logo.png" style="width: 40px;margin-right: 130px;margin-top: 10px;height: 40px;border-radius: 40px" alt="图片"/></i>
        </div>
        <div style="display: flex;justify-content: flex-start;width: 180px;text-align: left;">
          <el-menu style="width: 180px;" unique-opened router>
            <template v-for="(item,index) in this.routes" v-if="!item.hidden">
              <el-submenu :key="index" :index="index+''">
                <template slot="title">
                  <i :class="item.iconCls" style="color: #20a0ff;width: 14px;"></i>
                  <!--  后端传来数据，侧边栏菜单  -->
                  <span slot="title">{{item.name}}</span>
                </template>
                <el-menu-item width="180px"
                              style="padding-left: 30px;padding-right:0px;margin-left: 4px;width: 170px;text-align: left"
                              v-for="child in item.children"
                              :index="child.path"
                              :key="child.path">{{child.name}}<!--  后端传来数据，侧边栏菜单目录  -->
                </el-menu-item>
              </el-submenu>
            </template>
          </el-menu>
        </div>
      </el-aside>
      <el-container>
        <el-header class="home-header" style="background-size: cover;">
          <span class="home_title">人力资源管理系统</span>
          <div style="display: flex;align-items: center;margin-right: 7px">
<!--            <el-badge style="margin-right: 30px" :is-dot="this.$store.state.nfDot">-->
<!--&lt;!&ndash;              <svg class="icon" aria-hidden="true" @click="goChat" style="cursor: pointer">&ndash;&gt;-->
<!--&lt;!&ndash;                <use xlink:href="#icon-tongzhi"></use>&ndash;&gt;-->
<!--&lt;!&ndash;              </svg>&ndash;&gt;-->
<!--              <i class="el-icon-bell" @click="goChat" style="cursor: pointer"></i>-->
<!--            </el-badge>-->
            <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link home_userinfo" style="display: flex;align-items: center">
              {{user.name}}
              <i><img v-if="user.userface!==''" :src="user.userface" style="width: 40px;height: 40px;margin-right: 5px;margin-left: 5px;border-radius: 40px" alt="图片"/></i>
            </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="userinfo">个人中心</el-dropdown-item>
                <!--              <el-dropdown-item>设置</el-dropdown-item>-->
                <el-dropdown-item command="logout">注销</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
        </el-header>
        <el-main style="background-size: cover;background-color: #FFFFFF">
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item v-text="this.$router.currentRoute.name"></el-breadcrumb-item>
          </el-breadcrumb>
          <div class="homeWelcome" v-if="this.$router.currentRoute.path=='/home'">
            欢迎进入系统，新一天的工作就要准备开始了！
          </div>
          <keep-alive>
            <router-view v-if="this.$route.meta.keepAlive"></router-view>
          </keep-alive>
          <router-view v-if="!this.$route.meta.keepAlive"></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default{
  mounted: function () {

  },
  methods: {
    handleCommand(cmd){
      var _this = this;
      if (cmd == 'logout') {
        this.$confirm('注销登录, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          _this.getRequest("/logout");
          _this.$store.commit('logout');
          _this.$router.replace({path: '/'});
        }).catch(() => {
          _this.$message({
            type: 'info',
            message: '取消'
          });
        });
      }else if (cmd === 'userinfo') {
        this.$router.push('/hrinfo');
      }
    }
  },
  data(){
    return {
      isDot: false
    }
  },
  computed: {
    user(){
      return this.$store.state.user;
    },
    routes(){
      return this.$store.state.routes
    }
  }
}
</script>
<style>
.home-container {
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
}

.home-header {
  background-color: #20a0ff;
  color: #333;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: content-box;
  padding: 0;
}

.home-aside {
  background-color: #FFFFFF;
  background-size: cover;
  /*background-image: url(https://masteryhh.oss-cn-beijing.aliyuncs.com/blog_img/202204261040642.png)*/
}

.home-main {
  background-color: #fff;
  color: #000;
  text-align: center;
  margin: 0px;
  padding: 0px;;
}
.homeWelcome {
  text-align: center;
  font-size: 30px;
  font-family: 微软雅黑;
  color: #409eff;
  padding-top: 50px;
}

.home_title {
  color: #ECECEC;
  font-size: 22px;
  display: inline;
  margin-left: 8px;
}

.home_userinfo {
  color: #fff;
  cursor: pointer;
}

.home_userinfoContainer {
  display: inline;
  margin-right: 20px;
}

.el-submenu .el-menu-item {
  width: 180px;
  min-width: 175px;
}
.icon {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
